using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for FastFoodBO
/// </summary>
public class FastFoodBO
{
	public FastFoodBO()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public DataTable GetAllMon()
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.[FoodId], T1.[FoodTypeId], T1.[Name], T1.[Unit], T1.[Cost], T1.[LabelId], T1.[Image], T1.Inventory";
        sql += " FROM [OFSSDB].[dbo].[FastFood] T1 WHERE IsDelete = 0";
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetSearchMon(string val)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.[FoodId], T1.[FoodTypeId], T1.[Name], T1.[Unit], T1.[Cost], T1.[LabelId], T1.[Image], T1.Inventory";
        sql += "  FROM ";
        sql += "  [OFSSDB].[dbo].[FastFood] T1 ,";
        sql += "  [OFSSDB].[dbo].[FoodType] T2 ";
        sql += "  WHERE ";
        sql += "  T1.FoodTypeId = T2.FoodTypeId AND";
        sql += "  T2.IsDelete = 0 and T1.IsDelete = 0";
        sql += "  AND ";
        sql += "  (T1.FoodId LIKE '%" + val + "%'";
        sql += "  OR T1.[Name] LIKE '%" + val + "%'";
        sql += "  OR T1.LabelId LIKE '%"+ val +"%'";
        sql += "  OR T1.Description LIKE '%" + val + "%'";
        sql += "  OR T1.FoodTypeId LIKE '%" + val + "%') ";               
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetSearchMon(string mamon,string tenmon,string mota)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.[FoodId], T1.[FoodTypeId], T1.[Name], T1.[Unit], T1.[Cost], T1.[LabelId], '../' + T1.[Image] as Image, T1.Inventory";
        sql += "  FROM ";
        sql += "  [OFSSDB].[dbo].[FastFood] T1";     
        sql += "  WHERE ";       
        sql += " T1.IsDelete = 0";
        if (!"".Equals(mamon))
        {
            sql += "  AND ";
            sql += "  T1.FoodId LIKE '%" + mamon + "%'";
        }
        if (!"".Equals(tenmon))
        {
            sql += "  AND ";
            sql += "  T1.Name LIKE '%" + tenmon + "%'";
        }
        if (!"".Equals(mota))
        {
            sql += "  AND ";
            sql += "  (T1.Description LIKE '%" + mota + "%' OR T1.LabelId LIKE '%" + mota + "%')";
        }
       
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetSearchMonOnTop()
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT TOP 6 T1.[FoodId], T1.[FoodTypeId], T1.[Name], T1.[Unit], T1.[Cost], T1.[LabelId], '../' + T1.[Image] as Image,T1.Inventory";
        sql += "  FROM ";
        sql += "  [OFSSDB].[dbo].[FastFood] T1";
        sql += "  WHERE ";
        sql += " T1.IsDelete = 0";   

        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetSearchKhachHang(string maKH, string tenKH, string dc)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.[name], T1.[username], T1.[birthday], T1.[phone], T1.[address]";
        sql += "  FROM ";
        sql += "  [OFSSDB].[dbo].[users] T1";
        sql += "  WHERE ";
        sql += " T1.ID > 0";
        if (!"".Equals(maKH))
        {
            sql += "  AND ";
            sql += "  T1.username LIKE '%" + maKH + "%'";
        }
        if (!"".Equals(tenKH))
        {
            sql += "  AND ";
            sql += "  T1.name LIKE '%" + tenKH + "%'";
        }
        if (!"".Equals(dc))
        {
            sql += "  AND ";
            sql += "  (T1.address LIKE '%" + dc + "%')";
        }

        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetSearchLoaiMon(string maloai, string tenloai)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.[FoodTypeId], T1.[Name]";
        sql += "  FROM ";
        sql += "  [OFSSDB].[dbo].[FoodType] T1";     
        sql += "  WHERE ";       
        sql += " T1.IsDelete = 0";
        if (!"".Equals(maloai))
        {
            sql += "  AND ";
            sql += "  T1.FoodTypeId LIKE '%" + maloai + "%'";
        }
        if (!"".Equals(tenloai))
        {
            sql += "  AND ";
            sql += "  T1.Name LIKE '%" + tenloai + "%'";
        }
               
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetSearchMenu(string maMenu,string tenMenu,string maMon)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.[MenuId], T1.[FoodId], T1.[Quantity], T1.[Name]";
        sql += "  FROM ";
        sql += "  [OFSSDB].[dbo].[Menu Detail] T1";     
        sql += "  WHERE ";       
        sql += " T1.IsDelete = 0";
        if (!"".Equals(tenMenu))
        {
            sql += "  AND ";
            sql += "  T1.Name LIKE '%" + tenMenu + "%'";
        }
        if (!"".Equals(maMenu))
        {
            sql += "  AND ";
            sql += "  T1.MenuId LIKE '%" + maMenu + "%'";
        }
        if (!"".Equals(maMon))
        {
            sql += "  AND ";
            sql += "  (T1.FoodId LIKE '%" + maMon + "%')";
        }
       
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetSearchMonUaThich(string mamon, string tenmon, string mota)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.[FoodId], T1.[FoodTypeId], T1.[Name], T1.[Unit], T1.[Cost], T1.[LabelId], '../' + T1.[Image] as Image, T1.Inventory";
        sql += "  FROM ";
        sql += "  [OFSSDB].[dbo].[FastFood] T1";
        sql += "  WHERE ";
        sql += " T1.IsDelete = 0";
        if (!"".Equals(mamon))
        {
            sql += "  AND ";
            sql += "  T1.FoodId LIKE '%" + mamon + "%'";
        }
        if (!"".Equals(tenmon))
        {
            sql += "  AND ";
            sql += "  T1.Name LIKE '%" + tenmon + "%'";
        }
        if (!"".Equals(mota))
        {
            sql += "  AND ";
            sql += "  (T1.Description LIKE '%" + mota + "%' OR T1.LabelId LIKE '%" + mota + "%')";
        }

        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetById(string id)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.[FoodId], T1.[FoodTypeId], T1.[Name], T1.[Unit], T1.[Cost], T1.[LabelId], T1.[Image], T1.Description, T1.Inventory";
        sql += " FROM [OFSSDB].[dbo].[FastFood] T1";
        sql += " WHERE IsDelete = 0 AND T1.FoodId = " + id;
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public DataTable GetByMenuId(string id)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "Select M.Cost as MenuCost, M.Name as MenuName, M.Inventory as luongton, FF.Name FFName from MenuDetail MD, Menu M, FastFood FF";
        sql += " where MenuId=" + id;
        sql += " and M.MenuId=MD.MenuId";
        sql += " and MD.FoodId=FF.FoodId";
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
    public void SuaMonAn(string ID, string[] listcol, object[] listobject)
    {
        DBconnect connect = new DBconnect();
        connect.Open();
        if (connect.IsConnected == false)
            return;
        int n = connect.Update("FastFood", listcol, listobject, "FoodId=@ID", "@ID", ID);
        connect.Close();        
    }
    public void XoaMonAn(String ID)
    {
        DBconnect connect = new DBconnect();
        connect.Open();
        if (connect.IsConnected == false)
            return;
        string[] listcol = new string[] { "IsDelete" };
        object[] listobject = new object[] { "1" };
        int n = connect.Update("FastFood", listcol, listobject, "FoodId=@ID", "@ID", ID);
        connect.Close();
    }

    public DataTable AllFoods()
    {
        DBconnect DB = new DBconnect();
        DB.Open();
        DataTable Tmp = new DataTable();
        Tmp = DB.GetDataTable("select * from FastFood Where isDelete = 0");
        DB.Close();
        return Tmp;
    }
    public DataTable AllFoodsFavorite(string customerId)
    {
        DBconnect DB = new DBconnect();
        DB.Open();
        DataTable Tmp = new DataTable();
        Tmp = DB.GetDataTable("select T1.* from FastFood T1, fastFoodFavorite T2 where T1.FoodId = T2.FoodId AND  T1.isDelete = 0 AND T2.IsDelete = 0 AND T2.customerId = " + customerId);
        DB.Close();
        return Tmp;        
    }
    
}
